package com.tangruojie.lambda;

import java.util.function.Function;

public class LambdaDemo04 {

    public static <R> R typeConvert(Function<String, R> function) {
        String s = "13579";
        return function.apply(s);
    }

    public static void main(String[] args) {

        /**
         * 返回字符串
         */
        String str = typeConvert(new Function<String, String>() {
            @Override
            public String apply(String s) {
                return s + "hello world";
            }
        });
        System.out.println(str);

        String strSimple = typeConvert(s -> s + "hello world");
        System.out.println(strSimple);

        /**
         * 返回数字
         */
        Integer integer = typeConvert(new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return s.length();
            }
        });
        System.out.println(integer);

        Integer integerSimple = typeConvert(String::length);
        System.out.println(integerSimple);

    }

}
